package com.itqf.demo01;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/15
 * @Time: 上午11:20
 */
public class QuartzDemo01 {

    public  static  void  main(String[]args) throws  Exception{

        //1,调度器  Scheduler
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        //2,触发器  Trigger  触发任务执行
        SimpleTrigger trigger = TriggerBuilder
                .newTrigger().withIdentity("myTrigger1","myGroup1")
                //.withSchedule(SimpleScheduleBuilder.simpleSchedule()  simpleTrigger
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5)//间隔时间
                // .repeatForever()//重复执行  永不停歇
                   .withRepeatCount(5)
                )
                .startNow()//立即开启
                //.endAt 结束时间 注意月从0开始算
                //.endAt(new GregorianCalendar(2020,10,15,11,44,30).getTime())
                .build();

        //3,工作详情对象  JobDetail
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJob","myGroup").build();

        //4.注册任务和触发器
        Date date =  scheduler.scheduleJob(jobDetail,trigger);

        //5.开启任务
        scheduler.start();
        System.out.println("任务开启："+date);

    }


}
